package com.citcc.web.controller.business;

import com.citcc.business.bean.CdzStation;
import com.citcc.business.bean.CdzWarn;
import com.citcc.business.bean.UserOrderEntity;
import com.citcc.business.bean.WarnExport;
import com.citcc.business.service.CdzStationService;
import com.citcc.business.service.CdzWarnService;
import com.citcc.common.annotation.Log;
import com.citcc.common.base.AjaxResult;
import com.citcc.common.enums.BusinessType;
import com.citcc.common.page.TableDataInfo;
import com.citcc.common.utils.DateUtils;
import com.citcc.common.utils.poi.ExcelUtil;
import com.citcc.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/cdzWarn")
public class CdzWarnController extends BaseController {

    private String prefix = "business/cdzWarn";

    @Autowired
    private CdzWarnService cdzWarnService;
    @Autowired
    private CdzStationService cdzStationService;

    @RequiresPermissions("business:cdzWarn:view")
    @GetMapping("/main")
    public String vehicle(ModelMap map){
        CdzStation station = new CdzStation();
        station.setOrgId(getSysUser().getDeptId());
        map.put("station",cdzStationService.selectCdzStationAll(station));
        return prefix + "/main";
    }

    @RequiresPermissions("business:cdzWarn:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(CdzWarn warn){
        startPage();
        List<WarnExport> list=cdzWarnService.selectAllList(warn);

        return getDataTable(list);
    }

    @RequiresPermissions("business:cdzWarn:export")
    @Log(title = "告警导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CdzWarn cdzWarn)
    {
        List<WarnExport> list=cdzWarnService.selectAllList(cdzWarn);
        ExcelUtil<WarnExport> util = new ExcelUtil<WarnExport>(WarnExport.class);
        return util.exportExcel(list, DateUtils.dateTimeNow()+"告警记录");
    }

}
